package Control;

import java.io.Serializable;
import java.util.ArrayList;

import GUI.GV;

public class Shape implements Serializable{

	public static final int firstCircular = Shapes.CIRCLE.ordinal();
	public static final int lastCircular = Shapes.CONE.ordinal();
	public static final int firstPolygonal = Shapes.TRIANGLE.ordinal();
	public static final int lastPolygonal = Shapes.DELTA.ordinal();
	public static final int firstLight = Shapes.LIGHT.ordinal();
	public static final int lastLight = Shapes.FLASH.ordinal();
	public static final int firstOther = Shapes.UNKNOWN.ordinal();
	public static final int lastOther = Shapes.CHANGING.ordinal();
	
	public enum Category {
		CIRCULAR, POLYGONAL, LIGHT, OTHER
	}
	public enum Shapes{
		CIRCLE,DISK,SPHERE,OVAL,CIGAR,CYLINDER,EGG,TEARDROP,CONE,TRIANGLE,
		FORMATION,RECTANGLE,DIAMOND,CHEVRON,CROSS,DELTA,LIGHT,FIREBALL,
		FLASH,UNKNOWN,OTHER,CHANGING
	}


	public final String name;
	public final Category category;
	public final Shapes shape;


	public String getName() {
		return name;
	}

	public Shape(Category category, Shapes shape){
		switch (shape){
		
		case CIRCLE: name = "Circle";break;
		case DISK: name = "Disk";break;
		case SPHERE: name = "Sphere";break;
		case UNKNOWN: name = "Unknown";break;
		case OTHER: name = "Other";break;
		case TRIANGLE: name = "Triangle";break;
		case FORMATION: name = "Formation";break;
		case OVAL: name = "Oval";break;
		case CIGAR: name = "Cigar";break;
		case CYLINDER: name = "Cylinder";break;
		case EGG: name = "Egg";break;
		case TEARDROP: name = "Teardrop";break;
		case CONE: name = "Cone";break;
		case RECTANGLE: name = "Rectangle";break;
		case DIAMOND: name = "Diamond";break;
		case CHEVRON: name = "Chevron";break;
		case CROSS: name = "Cross";break;
		case DELTA: name = "Delta";break;
		case LIGHT: name = "Light";break;
		case FIREBALL: name = "Fireball";break;
		case FLASH: name = "Flash";break;
		//case CHANGING: name = "Changing";break;
		default: name ="Changing"; break;
		}

		this.shape = shape;
		this.category = category;

	}

	public boolean equals(Shape other) {
		if (this == other)
			return true;
		if (other == null)
			return false;
		if (shape != other.shape)
			return false;
		return true;
	}

	public Shapes getShapeIndex() {
		return shape;
	}

	public Category getCategory() {
		return category;
	}

	public static Shapes getShapesEnumFromName(String name) throws Exception{
		Shapes s = null;

		if(name.isEmpty())
		{
			//if name is empty set it to unknown shape
			s=GV.shapes.get(19).shape;
		}
		for(int i=0;i<GV.shapes.size();i++){
			if(name.equalsIgnoreCase(GV.shapes.get(i).getName())){
				s = GV.shapes.get(i).shape;
				break;
			}
		}
		if(s==null && name.equalsIgnoreCase("dome"))
		{
			s=GV.shapes.get(19).shape;
		}
		if(s==null) throw new Exception("shape not found: "+name);
		return s;
	}
	
	
	public static Shapes getShapesEnumFromName(ArrayList<Shape> thisShapes,String name) throws Exception{
		Shapes s = null;

		if(name.isEmpty())
		{
			//if name is empty set it to unknown shape
			s=thisShapes.get(19).shape;
		}
		for(int i=0;i<thisShapes.size();i++){
			if(name.equalsIgnoreCase(thisShapes.get(i).getName())){
				s = thisShapes.get(i).shape;
				break;
			}
		}
		if(s==null && name.equalsIgnoreCase("dome"))
		{
			s=thisShapes.get(19).shape;
		}
		if(s==null) throw new Exception("shape not found: "+name);
		return s;
	}



	public static void initShapes(){
		GV.shapes = new ArrayList<Shape>();
		GV.shapes.add(new Shape(Category.CIRCULAR,Shapes.CIRCLE));
		GV.shapes.add(new Shape(Category.CIRCULAR,Shapes.DISK));
		GV.shapes.add(new Shape(Category.CIRCULAR,Shapes.SPHERE));
		GV.shapes.add(new Shape(Category.CIRCULAR,Shapes.OVAL));
		GV.shapes.add(new Shape(Category.CIRCULAR,Shapes.CIGAR));
		GV.shapes.add(new Shape(Category.CIRCULAR,Shapes.CYLINDER));
		GV.shapes.add(new Shape(Category.CIRCULAR,Shapes.EGG));
		GV.shapes.add(new Shape(Category.CIRCULAR,Shapes.TEARDROP));
		GV.shapes.add(new Shape(Category.CIRCULAR,Shapes.CONE));
		//GV.shapes.add(new Shape("Round",,Category.CIRCULAR));
		//GV.shapes.add(new Shape("Crescent",,Category.CIRCULAR));
		//GV.shapes.add(new Shape("Dome",,Category.CIRCULAR));


		GV.shapes.add(new Shape(Category.POLYGONAL,Shapes.TRIANGLE));
		GV.shapes.add(new Shape(Category.POLYGONAL,Shapes.FORMATION));
		GV.shapes.add(new Shape(Category.POLYGONAL,Shapes.RECTANGLE));
		GV.shapes.add(new Shape(Category.POLYGONAL,Shapes.DIAMOND));
		GV.shapes.add(new Shape(Category.POLYGONAL,Shapes.CHEVRON));
		GV.shapes.add(new Shape(Category.POLYGONAL,Shapes.CROSS));
		GV.shapes.add(new Shape(Category.POLYGONAL,Shapes.DELTA));
		//GV.shapes.add(new Shape("Pyramid",,Category.POLYGONAL);
		//GV.shapes.add(new Shape("Exagon",,Category.POLYGONAL));

		GV.shapes.add(new Shape(Category.LIGHT,Shapes.LIGHT));
		GV.shapes.add(new Shape(Category.LIGHT,Shapes.FIREBALL));
		GV.shapes.add(new Shape(Category.LIGHT,Shapes.FLASH));
		//GV.shapes.add(new Shape("Flare",,Category.LIGHT));

		GV.shapes.add(new Shape(Category.OTHER,Shapes.UNKNOWN)); //blank also grouped in unknown
		GV.shapes.add(new Shape(Category.OTHER,Shapes.OTHER));
		GV.shapes.add(new Shape(Category.OTHER,Shapes.CHANGING)); //changed here too
	}
	
	public static ArrayList<Shape> returnShapes()
	{
		ArrayList<Shape> myShapes = new ArrayList<Shape>();
		myShapes.add(new Shape(Category.CIRCULAR,Shapes.CIRCLE));
		myShapes.add(new Shape(Category.CIRCULAR,Shapes.DISK));
		myShapes.add(new Shape(Category.CIRCULAR,Shapes.SPHERE));
		myShapes.add(new Shape(Category.CIRCULAR,Shapes.OVAL));
		myShapes.add(new Shape(Category.CIRCULAR,Shapes.CIGAR));
		myShapes.add(new Shape(Category.CIRCULAR,Shapes.CYLINDER));
		myShapes.add(new Shape(Category.CIRCULAR,Shapes.EGG));
		myShapes.add(new Shape(Category.CIRCULAR,Shapes.TEARDROP));
		myShapes.add(new Shape(Category.CIRCULAR,Shapes.CONE));
		//GV.shapes.add(new Shape("Round",,Category.CIRCULAR));
		//GV.shapes.add(new Shape("Crescent",,Category.CIRCULAR));
		//GV.shapes.add(new Shape("Dome",,Category.CIRCULAR));


		myShapes.add(new Shape(Category.POLYGONAL,Shapes.TRIANGLE));
		myShapes.add(new Shape(Category.POLYGONAL,Shapes.FORMATION));
		myShapes.add(new Shape(Category.POLYGONAL,Shapes.RECTANGLE));
		myShapes.add(new Shape(Category.POLYGONAL,Shapes.DIAMOND));
		myShapes.add(new Shape(Category.POLYGONAL,Shapes.CHEVRON));
		myShapes.add(new Shape(Category.POLYGONAL,Shapes.CROSS));
		myShapes.add(new Shape(Category.POLYGONAL,Shapes.DELTA));
		//GV.shapes.add(new Shape("Pyramid",,Category.POLYGONAL);
		//GV.shapes.add(new Shape("Exagon",,Category.POLYGONAL));

		myShapes.add(new Shape(Category.LIGHT,Shapes.LIGHT));
		myShapes.add(new Shape(Category.LIGHT,Shapes.FIREBALL));
		myShapes.add(new Shape(Category.LIGHT,Shapes.FLASH));
		//GV.shapes.add(new Shape("Flare",,Category.LIGHT));

		myShapes.add(new Shape(Category.OTHER,Shapes.UNKNOWN)); //blank also grouped in unknown
		myShapes.add(new Shape(Category.OTHER,Shapes.OTHER));
		myShapes.add(new Shape(Category.OTHER,Shapes.CHANGING)); //changed here too
		
		return myShapes;
	}

	
}
